//
//  AppDelegate.m
//  operator
//
//  Created by Andrej on 21.12.11.
//  Copyright (c) 2011 RWTH Aachen. All rights reserved.
//

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;

- (void)dealloc {
    [super dealloc];
}

-(void) applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSLog(@"Open network connection");
    
    #if OFFLINE != 1
        /* set up connection to the server (no error handling yet) */
        [[NetworkingCenter defaultServer] openConnectionToServer];
    #endif
}

-(void) applicationWillTerminate:(NSNotification *)notification {
    NSLog(@"Logout...");

    //[[NetworkingCenter defaultServer] sendMessage:[NetworkMessageCreator logoutMessage]];
    // This was removed since server crashes! Don't know why?!

    /* close connection */
    if([[NetworkingCenter defaultServer] isRunning]) {
        [[NetworkingCenter defaultServer] closeConnectionToServer];
        sleep(1);
    }
}

-(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
    return YES;
}

@end
